
<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
</head>
<body>
	<form action="1.php" method="post" id ='form'>
	<input type ="text" id="uname" value=""><span>请输入8~16的数字字母下划线</span><br /><br />
	<input type="text" id ="tet"><br /><br/>
	<select name="" id="sel">
		<option value="北京">ds</option>
		<option value="上单">fds</option>
		<option value="北河">fd</option>
		<option value="sd">f</option>
		<option value="fsd">fd</option>
	</select>>
	<input type ="submit" value="提交"><br/><br/>
	<input type="reset" value ="重置">
	</form>
	<script type="text/javascript">
	//获取元素
	var uname =document.getElementById('uname');

	var sel = document.getElementById('sel');

	var tet =document.getElementById('tet');

	var form =document.getElementById('form');

	uname.onfocus =function()
	{
		//获取值
		var v =this.value;

		//正则匹配

		var reg =/^\w{8,19}$/;

		if(reg.test(v)){
			this.style.border ='solid 2px green';
		}else {
			this.style.border ='solid 2px red';
		}
	}

	//当下拉框的值改变的时候 触发
	sel.onchange =function()
	{
	alert('111');
	}
	tet.onselect =function()
	{
	alert('111');
	}
	tet.oncopy =function()alert('111');
	{
	alert('111');
	}

	form.onsubmit =function()
	{
	alert('111');
	}

	form.onreset =function()

	{
		alert('111');
	}



	</script>
</body>
</html>